package cn.hlife.com.hlfhaemocyte;

import android.bluetooth.BluetoothDevice;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Typeface;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry;
import com.greendaodemo.greendao.gen.DaoMaster;
import com.greendaodemo.greendao.gen.DaoSession;
import com.greendaodemo.greendao.gen.MeasureEntityDao;
import com.utils.LogUtils;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import cn.hlife.com.bluetooth20_connect.lib.BluetoothService;
import cn.hlife.com.hlfhaemocyte.bean.MeasureEntity;
import cn.hlife.com.hlfhaemocyte.utils.RDPrinterInterface;

public class TestViewActivity extends AppCompatActivity {
    private BluetoothService mService = null;
    ImageView imageView;
    BluetoothDevice con_dev = null;
    RDPrinterInterface mRDPrinterInterface;
    int landscape = 130, startscape = 20;//横向的间隔
    int verticalHigh = 25, startvertical = 20;//纵向间隔
    RelativeLayout relativeLayout;
    Button button;
    /**
     * 创建一个Handler实例，用于接收BluetoothService类返回回来的消息
     */
    private final Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case BluetoothService.MESSAGE_STATE_CHANGE:
                    switch (msg.arg1) {
                        case BluetoothService.STATE_CONNECTED:   //已连接
                            LogUtils.e("蓝牙打印机连接成功");
                            Toast.makeText(getApplicationContext(), "蓝牙打印机连接成功",
                                    Toast.LENGTH_SHORT).show();
                            break;
                        case BluetoothService.STATE_CONNECTING:  //正在连接
                            LogUtils.e("蓝牙调试   正在连接.....");
                            break;
                        case BluetoothService.STATE_LISTEN:     //监听连接的到来
                        case BluetoothService.STATE_NONE:
                            LogUtils.e("蓝牙调试  等待连接.....");
                            break;
                    }
                    break;
                case BluetoothService.MESSAGE_CONNECTION_LOST:    //蓝牙已断开连接
                    Toast.makeText(getApplicationContext(), "蓝牙打印机已断开",
                            Toast.LENGTH_SHORT).show();
                    break;
                case BluetoothService.MESSAGE_UNABLE_CONNECT:     //无法连接设备

                    Toast.makeText(getApplicationContext(), "蓝牙打印机连接失败！",
                            Toast.LENGTH_SHORT).show();

                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_view);
//        LineChart chart = (LineChart) findViewById(R.id.chart);
        imageView = (ImageView) findViewById(R.id.imageView);
        final Bitmap bitmap = createReportBitmap();
//        final Bitmap bitmap = getBitMap();
        imageView.setImageBitmap(bitmap);
        button = (Button) findViewById(R.id.button2);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                con_dev = mService.getDevByMac("00:BA:55:81:DB:A8");
                if (con_dev != null) {
                    mService.connect(con_dev);
                } else {
                    Toast.makeText(getApplicationContext(), "没有找到该设备",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
        findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    alignCenter();
                    PrintBitmap(bitmap);


                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
        mRDPrinterInterface = RDPrinterInterface.getInstance();
        mService = new BluetoothService(this, handler);
        relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
    }

    public Bitmap getBitMap() {
        LinearLayout linearLayout = new LinearLayout(this);
        LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
                384, 384);
        linearLayout.setLayoutParams(param);
        linearLayout.setBackgroundColor(Color.parseColor("#FFFF6600"));
        linearLayout.setOrientation(LinearLayout.VERTICAL);
//        LineChart  lineChart=new LineChart(this);
//        linearLayout.addView(lineChart);
        TextView textView = new TextView(this);
        textView.setText("下午干活");
        linearLayout.addView(textView);
        return convertViewToBitmap(button);
    }

    public Bitmap convertViewToBitmap(View view) {
        Bitmap bitmap = Bitmap.createBitmap(384, 384,
                Bitmap.Config.ARGB_8888);
        //利用bitmap生成画布
        Canvas canvas = new Canvas(bitmap);
        //把view中的内容绘制在画布上
        view.draw(canvas);
        return bitmap;
    }

    private Bitmap getViewBitmap(View v) {
        v.clearFocus();
        v.setPressed(false);

        boolean willNotCache = v.willNotCacheDrawing();
        v.setWillNotCacheDrawing(false);

        // Reset the drawing cache background color to fully transparent
        // for the duration of this operation
        int color = v.getDrawingCacheBackgroundColor();
        v.setDrawingCacheBackgroundColor(Color.WHITE);

        if (color != 0) {
            v.destroyDrawingCache();
        }
        v.buildDrawingCache();
        Bitmap cacheBitmap = v.getDrawingCache();
        if (cacheBitmap == null) {
            Log.e("Folder", "failed getViewBitmap(" + v + ")", new RuntimeException());
            return null;
        }

        Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);

        // Restore the view
        v.destroyDrawingCache();
        v.setWillNotCacheDrawing(willNotCache);
        v.setDrawingCacheBackgroundColor(color);
        Matrix matrix = new Matrix();
        matrix.postScale(0.8f, 0.8f);
        matrix.postRotate(90);
        Bitmap bm = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
                bitmap.getHeight(), matrix, true);

        return bm;
    }

    //居中
    public void alignCenter() throws IOException {
        mService.write(RDPrinterInterface.MIND);
    }

    public void PrintBitmap(Bitmap bitmap) throws IOException {
        // TODO Auto-generated method stub
        byte[] add = RDPrinterInterface.getByteArray(0x00);
        int[] sourceData = mRDPrinterInterface.getBitmapData(bitmap);
        byte[] data = RDPrinterInterface.getByteArray(sourceData);
        //byte[] imgCmd = RDPrinterInterface.getByteArray(0x1B, 0x31, 0);
        //Write(imgCmd);
        LineSpace_SET(add[0]);//行间距

        int sendLen = bitmap.getWidth();//
        byte[] ImageCMD = mRDPrinterInterface.getImageCmd(RDPrinterInterface.IMAGECMD, sendLen);

        for (int i = 0; i < data.length / sendLen; i++) {
            byte[] temp = Arrays.copyOfRange(data, i * sendLen, (i + 1)
                    * sendLen);
            byte[] stemp = RDPrinterInterface.concat(temp, RDPrinterInterface.WRAP_PRINT);
            byte[] printData = RDPrinterInterface.concat(ImageCMD, stemp);
            Log.v("wmg", i + "  ,printData len = " + printData.length);

            Write(printData);
        }
    }

    private void Write(byte[] command) throws IOException {
        Log.d("TEST->", " mUartManager.write(command);");
        int maxLenth = 1024;
        int count = command.length / maxLenth;
        byte[] buffer = null;
        for (int i = 0; i <= count; i++) {
            if (i < count) {
                buffer = Arrays.copyOfRange(command, i * maxLenth, (i + 1)
                        * maxLenth);
            } else {
                buffer = Arrays.copyOfRange(command, i * maxLenth,
                        command.length);
            }
            mService.write(buffer);
            /*
             * sleepThread(80); //M:TIM 20140924 byte[] temp = new byte[1];
			 * mUartManager.read_mini(temp); if (temp[0] == 0x15) { throw new
			 * NoPaperException("no paper"); }
			 */
        }
    }

    //打印字体／图片行间距设置 0x00～0xFF
    //打印图片设置为0x0
    //打印文字参考设置为0x5
    public void LineSpace_SET(byte sp) throws IOException {
        byte[] PRINT_LINESPACE_SET = new byte[3];
        System.arraycopy(RDPrinterInterface.PRINT_LINESPACE, 0, PRINT_LINESPACE_SET, 0, RDPrinterInterface.PRINT_LINESPACE.length);
        PRINT_LINESPACE_SET[2] = sp;

        mService.write(PRINT_LINESPACE_SET);
    }
//    public Bitmap  createChartBitMap(){
//        Bitmap bitmap = Bitmap.createBitmap(1000, 384, Bitmap.Config.ARGB_4444);
//        Canvas canvas = new Canvas(bitmap);
//        canvas.drawColor(Color.parseColor("#FFFFFFFF"));
//        LineChart  lineChart=new  LineChart(this);
//
//        return null;
//    };


    /**
     * 画所有横向表格，包括X轴
     */
    private void drawAllXLine(Canvas canvas) {
        //创建dbmanager类初始化数据库
        DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(this.getApplicationContext(), "user.db", null);
        DaoMaster daoMaster = new DaoMaster(devOpenHelper.getWritableDb());
        DaoSession daoSession = daoMaster.newSession();
        MeasureEntityDao measureEntityDao = daoSession.getMeasureEntityDao();
        List<MeasureEntity> listAll = measureEntityDao.queryBuilder()
                .orderDesc(MeasureEntityDao.Properties.Id)
                .list();
//        MeasureEntity measureEntity = measureEntityDao.queryBuilder()
//                .where(MeasureEntityDao.Properties.Id.eq(id)).unique();
//        String temp;
//        temp = stringData.replace("[", "");
//        temp = temp.replace("]", "");
//        String[] strArray = temp.split(",");
//        ArrayList<Entry> array = new ArrayList<Entry>();
//        float sumNumber = 0;
//        for (int i = 0; i < strArray.length; i++) {
//            sumNumber += Float.valueOf(strArray[i]);
//            if (i % 5 == 0) {
//                array.add(new Entry(i, sumNumber));
//                sumNumber = 0;
//            }
//        }
        //可变参数  左侧的最大值
        //距离左边距的距离
//        int startX=930+15;
        int marginLeft=15;
        int startX = 500 + marginLeft;
        int marginTop= 10;
        int marginBottom= 10;
        int charWidth = 384;
        int charHigh = (384-marginTop-marginBottom) / 3;
        //横向的间距
        int spacingwidth;
        //纵向的间距
        int spacingHeight;

        // 横向 纵向的个数
        int averageXValue = 20, averageYValue = 5;

        spacingwidth = charWidth / averageXValue;
        spacingHeight = charHigh / averageYValue;

        int endX = startX + charWidth;
        int endY = charHigh;

        Paint mPaint = new Paint();
        mPaint.setColor(Color.RED);
        mPaint.setStrokeWidth(1.0f);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setAntiAlias(true);
//        for (int i = 0; i < averageXValue; i++) {
//            drawText(String.valueOf(averageValue * i), blwidh / 2, bheight - (bheight / spacingHeight) * i + marginTop,
//                    canvas);
//        }
        canvas.drawLine(startX, charHigh, endX,
        endY, mPaint);

        canvas.drawLine(startX, charHigh*2, endX,
        endY*2, mPaint);

        canvas.drawLine(startX, charHigh*3, endX,
                endY*3, mPaint);
        endX=startX;
        endY= marginTop+charHigh;
        canvas.drawLine(startX, marginTop, endX,
                endY, mPaint);
    }

    public Bitmap createReportBitmap() {
        Bitmap bitmap = Bitmap.createBitmap(1000, 384, Bitmap.Config.ARGB_4444);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawColor(Color.LTGRAY);
        drawAllXLine(canvas);


//        String testStr = "检验报告单";
//        Bitmap bitmap = Bitmap.createBitmap(1000, 384, Bitmap.Config.ARGB_4444);
//        Canvas canvas = new Canvas(bitmap);
//        canvas.drawColor(Color.parseColor("#FFFFFFFF"));
//        TextPaint textPaint = new TextPaint();
//        textPaint.setAntiAlias(true);
//        textPaint.setTextSize(20.0F);
//        canvas.drawText(testStr, 400, startvertical, textPaint);
//        textPaint.setTextSize(16.0F);
//        textPaint.setStrokeWidth((float) 0.5);
//        Typeface  mTf= Typeface.createFromAsset(getAssets(), "fonts/苹果iOS9苹方纤细体UltraLight_50868_S60SC_C.ttf");
//        textPaint.setTypeface(mTf);
//        testStr="姓     名:";
//        canvas.drawText(testStr, startscape, verticalHigh+startvertical, textPaint);
//        testStr="性     别:";
//        canvas.drawText(testStr, startscape+landscape, verticalHigh+startvertical, textPaint);
//        testStr="病床号:";
//        canvas.drawText(testStr, startscape+landscape*2-10, verticalHigh+startvertical, textPaint);
//        testStr="科     室:";
//        canvas.drawText(testStr, startscape+landscape*3-30-20, verticalHigh+startvertical, textPaint);
//        testStr="病 历 号:";
//        canvas.drawText(testStr, startscape+landscape*4+20, verticalHigh+startvertical, textPaint);
//        testStr="样 本 号:";
//        canvas.drawText(testStr, startscape+landscape*5+50, verticalHigh+startvertical, textPaint);
//        /**--------------------------------------------------------------------------------------------------------------*/
//        testStr="送检标本:";
//        canvas.drawText(testStr, startscape, verticalHigh*2+startvertical, textPaint);
//        testStr="送检医生:";
//        canvas.drawText(testStr, startscape+landscape, verticalHigh*2+startvertical, textPaint);
//
//        testStr="年  龄:";
//        canvas.drawText(testStr, startscape+landscape*2-10, verticalHigh*2+startvertical, textPaint);
//        testStr="送检时间:";
//        canvas.drawText(testStr, startscape+landscape*3-30-20, verticalHigh*2+startvertical, textPaint);
//        testStr="临床诊断:";
//        canvas.drawText(testStr, startscape+landscape*4+20, verticalHigh*2+startvertical, textPaint);
//        testStr="备    注:";
//        canvas.drawText(testStr, startscape+landscape*5+50, verticalHigh*2+startvertical, textPaint);
//        testStr="-----------------------------------------------------------------------------------------";
//        canvas.drawText(testStr, 20, verticalHigh*3+startvertical-10, textPaint);
//        /**--------------------------------------------------------------------------------------------------------------*/
//
//        testStr="项目";
//        canvas.drawText(testStr, startscape+10, verticalHigh*3+startvertical, textPaint);
//        testStr="结果";
//        canvas.drawText(testStr, startscape+landscape+100, verticalHigh*3+startvertical, textPaint);
//        testStr="单位";
//        canvas.drawText(testStr, startscape+landscape*2+30, verticalHigh*3+startvertical, textPaint);
//        testStr="参考值";
//        canvas.drawText(testStr, startscape+landscape*3-30, verticalHigh*3+startvertical, textPaint);
//
//
//        testStr="WBC 白细胞";
//        canvas.drawText(testStr, startscape+10, verticalHigh*4+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape+100, verticalHigh*4+startvertical, textPaint);
//        testStr="x10"+"⁹"+"/L";
//        canvas.drawText(testStr, startscape+landscape*2+30, verticalHigh*4+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*3-30, verticalHigh*4+startvertical, textPaint);
//
//        testStr="LYM# 淋巴细胞数";
//        canvas.drawText(testStr, startscape+10, verticalHigh*5+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape+100, verticalHigh*5+startvertical, textPaint);
//        testStr="x10"+"⁹"+"/L";
//        canvas.drawText(testStr, startscape+landscape*2+30, verticalHigh*5+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*3-30, verticalHigh*5+startvertical, textPaint);
//
//        testStr="MON# 单核细胞数";
//        canvas.drawText(testStr, startscape+10, verticalHigh*6+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape+100, verticalHigh*6+startvertical, textPaint);
//        testStr="x10"+"⁹"+"/L";
//        canvas.drawText(testStr, startscape+landscape*2+30, verticalHigh*6+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*3-30, verticalHigh*6+startvertical, textPaint);
//
//
//        testStr="GRA# 粒细胞数";
//        canvas.drawText(testStr, startscape+10, verticalHigh*7+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape+100, verticalHigh*7+startvertical, textPaint);
//        testStr="x10"+"⁹"+"/L";
//        canvas.drawText(testStr, startscape+landscape*2+30, verticalHigh*7+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*3-30, verticalHigh*7+startvertical, textPaint);
//
//
//        testStr="LYM% 淋巴细胞百分比";
//        canvas.drawText(testStr, startscape+10, verticalHigh*8+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape+100, verticalHigh*8+startvertical, textPaint);
//        testStr="%";
//        canvas.drawText(testStr, startscape+landscape*2+30, verticalHigh*8+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*3-30, verticalHigh*8+startvertical, textPaint);
//
//        testStr="MON% 单核细胞百分比";
//        canvas.drawText(testStr, startscape+10, verticalHigh*9+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape+100, verticalHigh*9+startvertical, textPaint);
//        testStr="%";
//        canvas.drawText(testStr, startscape+landscape*2+30, verticalHigh*9+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*3-30, verticalHigh*9+startvertical, textPaint);
//
//        testStr="GRA% 粒细胞百分比";
//        canvas.drawText(testStr, startscape+10, verticalHigh*10+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape+100, verticalHigh*10+startvertical, textPaint);
//        testStr="%";
//        canvas.drawText(testStr, startscape+landscape*2+30, verticalHigh*10+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*3-30, verticalHigh*10+startvertical, textPaint);
//
//        testStr="HGB 血红蛋白";
//        canvas.drawText(testStr, startscape+10, verticalHigh*11+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape+100, verticalHigh*11+startvertical, textPaint);
//        testStr="g/L";
//        canvas.drawText(testStr, startscape+landscape*2+30, verticalHigh*11+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*3-30, verticalHigh*11+startvertical, textPaint);
//
//        testStr="MCH 平均血红蛋白含量";
//        canvas.drawText(testStr, startscape+10, verticalHigh*12+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape+100, verticalHigh*12+startvertical, textPaint);
//        testStr="P/g";
//        canvas.drawText(testStr, startscape+landscape*2+30, verticalHigh*12+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*3-30, verticalHigh*12+startvertical, textPaint);
//
//        testStr="MCHC 平均血红蛋白浓度";
//        canvas.drawText(testStr, startscape+10, verticalHigh*13+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape+100, verticalHigh*13+startvertical, textPaint);
//        testStr="g/L";
//        canvas.drawText(testStr, startscape+landscape*2+30, verticalHigh*13+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*3-30, verticalHigh*13+startvertical, textPaint);
//        testStr="-----------------------------------------------------------------------------------------";
//        canvas.drawText(testStr, 20, verticalHigh*14+startvertical-10, textPaint);
//        /**------------------------------------------------------------------------------------------------*/
//
//
//        testStr="项目";
//        canvas.drawText(testStr, startscape+landscape*3-30+100, verticalHigh*3+startvertical, textPaint);
//        testStr="结果";
//        canvas.drawText(testStr, startscape+landscape*5+20, verticalHigh*3+startvertical, textPaint);
//        testStr="单位";
//        canvas.drawText(testStr, startscape+landscape*4+210, verticalHigh*3+startvertical, textPaint);
//        testStr="参考值";
//        canvas.drawText(testStr, startscape+landscape*5+150, verticalHigh*3+startvertical, textPaint);
//
//        testStr="RBC 红细胞";
//        canvas.drawText(testStr, startscape+landscape*3-30+100, verticalHigh*4+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape*5+20, verticalHigh*4+startvertical, textPaint);
//        testStr="x10¹²/L";
//        canvas.drawText(testStr, startscape+landscape*4+210, verticalHigh*4+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*5+150, verticalHigh*4+startvertical, textPaint);
//
//        testStr="MCV 平均红细胞体积";
//        canvas.drawText(testStr, startscape+landscape*3-30+100, verticalHigh*5+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape*5+20, verticalHigh*5+startvertical, textPaint);
//        testStr="f/L";
//        canvas.drawText(testStr, startscape+landscape*4+210, verticalHigh*5+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*5+150, verticalHigh*5+startvertical, textPaint);
//
//        testStr="HCT 红细胞压积";
//        canvas.drawText(testStr, startscape+landscape*3-30+100, verticalHigh*6+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape*5+20, verticalHigh*6+startvertical, textPaint);
//        testStr="%";
//        canvas.drawText(testStr, startscape+landscape*4+210, verticalHigh*6+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*5+150, verticalHigh*6+startvertical, textPaint);
//
//        testStr="PDWSD 红细胞分布宽度SD";
//        canvas.drawText(testStr, startscape+landscape*3-30+100, verticalHigh*7+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape*5+20, verticalHigh*7+startvertical, textPaint);
//        testStr="f/L";
//        canvas.drawText(testStr, startscape+landscape*4+210, verticalHigh*7+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*5+150, verticalHigh*7+startvertical, textPaint);
//
//        testStr="PDWCV 红细胞分布宽度CV";
//        canvas.drawText(testStr, startscape+landscape*3-30+100, verticalHigh*8+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape*5+20, verticalHigh*8+startvertical, textPaint);
//        testStr="%";
//        canvas.drawText(testStr, startscape+landscape*4+210, verticalHigh*8+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*5+150, verticalHigh*8+startvertical, textPaint);
//
//        testStr="PLT 血小板";
//        canvas.drawText(testStr, startscape+landscape*3-30+100, verticalHigh*9+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape*5+20, verticalHigh*9+startvertical, textPaint);
//        testStr="x10⁹/L";
//        canvas.drawText(testStr, startscape+landscape*4+210, verticalHigh*9+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*5+150, verticalHigh*9+startvertical, textPaint);
//
//        testStr="PCT 血小板压积";
//        canvas.drawText(testStr, startscape+landscape*3-30+100, verticalHigh*10+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape*5+20, verticalHigh*10+startvertical, textPaint);
//        testStr="%";
//        canvas.drawText(testStr, startscape+landscape*4+210, verticalHigh*10+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*5+150, verticalHigh*10+startvertical, textPaint);
//
//        testStr="MPV 平均血小板体积";
//        canvas.drawText(testStr, startscape+landscape*3-30+100, verticalHigh*11+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape*5+20, verticalHigh*11+startvertical, textPaint);
//        testStr="f/L";
//        canvas.drawText(testStr, startscape+landscape*4+210, verticalHigh*11+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*5+150, verticalHigh*11+startvertical, textPaint);
//
//        testStr="PDW 血小板分布宽度";
//        canvas.drawText(testStr, startscape+landscape*3-30+100, verticalHigh*12+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape*5+20, verticalHigh*12+startvertical, textPaint);
//        testStr="f/L";
//        canvas.drawText(testStr, startscape+landscape*4+210, verticalHigh*12+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*5+150, verticalHigh*12+startvertical, textPaint);
//
//        testStr="P-LCR 大血小板比率";
//        canvas.drawText(testStr, startscape+landscape*3-30+100, verticalHigh*13+startvertical, textPaint);
//        testStr="9.2";
//        canvas.drawText(testStr, startscape+landscape*5+20, verticalHigh*13+startvertical, textPaint);
//        testStr="%";
//        canvas.drawText(testStr, startscape+landscape*4+210, verticalHigh*13+startvertical, textPaint);
//        testStr="4.0-10.0";
//        canvas.drawText(testStr, startscape+landscape*5+150, verticalHigh*13+startvertical, textPaint);
//        /**------------------------------------------------------------------------------------------------*/
//        testStr="此样本仅对此标本负责";
//        canvas.drawText(testStr, startscape, verticalHigh*14+startvertical, textPaint);
//        testStr="检验员:";
//        canvas.drawText(testStr, startscape+landscape*3-30+100, verticalHigh*14+startvertical, textPaint);
//        testStr="复核员:";
//        canvas.drawText(testStr, startscape+landscape*5+50, verticalHigh*14+startvertical, textPaint);

        Matrix matrix = new Matrix();
        matrix.postScale(1f, 1f);
//        matrix.postRotate(90);
        Bitmap bm = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
                bitmap.getHeight(), matrix, true);
        return bm;
    }

}
